/**
 * 
 */
package org.youisoft.summer.evaluator.function.transport;

import org.youisoft.summer.evaluator.InvokeException;
import org.youisoft.summer.evaluator.connector.Connector;
import org.youisoft.summer.evaluator.connector.http.HttpConnector;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.function.AbstractFunction;
import org.youisoft.summer.evaluator.operator.Operator;
import org.youisoft.summer.evaluator.operator.base.MapOperator;
import org.youisoft.summer.evaluator.operator.base.ObjectOperator;
import org.youisoft.summer.evaluator.operator.base.StringOperator;

/**
 * @author zijiang.jl
 *
 */
public class HttpFunction extends AbstractFunction{
	@Override
	protected boolean checkOperator(int index, Operator<?> operator) {
		if(index==0&&StringOperator.class.isAssignableFrom(operator.getClass())) return true;
		if(MapOperator.class.isAssignableFrom(operator.getClass())) return true;
		return false;
	}
	
	@Override
	public <C, R, P> Operator<?> doInvoke(CalContext<C, R, P> context,
			Operator<?>... operator) throws InvokeException {
		System.out.println("in HttpFunction");
		StringOperator so=StringOperator.class.cast(operator[0]);
		HttpConnector tc=this.find(so.value(), HttpConnector.class);
		return new ObjectOperator<Connector>().setValue(tc);
	}
	
	
}
